
namespace ShoppingCart.WebSite.Code
{
    using System.Collections.Generic;
    using System.Web.UI.WebControls;

    public static class BindControl<T> where T : class
    {
        public static void BindDropDownList(DropDownList list, IList<T> source)
        {
            list.Items.Clear();
            list.DataSource = source;
            list.DataValueField = "Id" + typeof(T).Name;
            list.DataTextField = "Nombre";
            list.DataBind();
        }

        public static void BindListBox(ListBox lbox, IList<T> source)
        {
            lbox.Items.Clear();
            lbox.DataSource = source;
            lbox.DataValueField = "Id" + typeof(T).Name;
            lbox.DataTextField = "Nombre";
            lbox.DataBind();
        }

        public static void BindGrid(GridView grid, IList<T> source)
        {
            grid.DataSource = source;
            grid.DataBind();
        }

        public static void BindListView(ListView lsvw, IList<T> source)
        {
            lsvw.DataSource = source;
            lsvw.DataBind();
        }

        public static void BindRepeater(Repeater rep, IList<T> source)
        {
            rep.DataSource = source;
            rep.DataBind();
        }

        public static void BindDataList(DataList dlist, IList<T> source)
        {
            dlist.DataKeyField = "Id" + typeof(T).Name;
            dlist.DataSource = source;
            dlist.DataBind();
        }
    }
}
